home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Programming / vahunz / source / ugly / ustring.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-17  |  3.3 KB  |  225 lines

  1. /*
  2.  * This source file is part of Vahunz,
  3.  * a tool to make source code un-/more legible.
  4.  *
  5.  *--------------------------------------------------------------------------
  6.  *
  7.  * Vahunz and the Ugly library are Copyright (C) 1998 by
  8.  * Thomas Aglassinger <agi@giga.or.at>
  9.  *
  10.  * All rights reserved.
  11.  *
  12.  * Refer to the manual for more information.
  13.  *
  14.  *--------------------------------------------------------------------------
  15.  *
  16.  * Ubiqx library is Copyright (C) 1991-1998 by
  17.  * Christopher R. Hertel <crh@ubiqx.mn.org>
  18.  *
  19.  * Ubiqx library is free software; you can redistribute it and/or
  20.  * modify it under the terms of the GNU Library General Public
  21.  * License as published by the Free Software Foundation; either
  22.  * version 2 of the License, or (at your option) any later version.
  23.  *
  24.  */
  25. #include <ctype.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <errno.h>
  30. #include "utypes.h"
  31. #include "umemory.h"
  32. #define i2K
  33. #include "ustring.h"
  34. int b1O(STRPTR s)
  35. {
  36. size_t b1B = strlen(s);
  37. int ch = 0;
  38. if (b1B)
  39. {
  40. ch = s[b1B - 1];
  41. }
  42. else
  43. {
  44. ch = 0;
  45. }
  46. return ch;
  47. }
  48. STRPTR v3N(t8B k0Q, STRPTR e9R, ULONG p8T)
  49. {
  50. STRPTR t7H = NULL;
  51. if (k0Q)
  52. {
  53. #if v2E
  54. t7H = (STRPTR) e3L(strlen(k0Q) + 1, e9R, p8T);
  55. #else
  56. t7H = (STRPTR) o4N(strlen(k0Q) + 1);
  57. #endif
  58. if (t7H) 
  59. strcpy(t7H, k0Q); 
  60. }
  61. return (t7H); 
  62. }
  63. STRPTR c3X(STRPTR s)
  64. {
  65. STRPTR e3N = s;
  66. if (s)
  67. for (; *s != '\0'; s++)
  68. *s = toupper(*s);
  69. return e3N;
  70. }
  71. int r0X(t8B s1, t8B s2)
  72. {
  73. #define c2J 1
  74. #if !c2J
  75. int b7N; 
  76. #endif
  77. unsigned char c1, c2; 
  78. size_t i = 0; 
  79. do
  80. {
  81. c1 = toupper(s1[i]);
  82. c2 = toupper(s2[i]);
  83. i++;
  84. }
  85. while (c1 && c2 && (c1 == c2));
  86. #if c2J
  87. return (c2 - c1);
  88. #else
  89. if (c1 < c2)
  90. b7N = -1; 
  91. else if (c1 > c2)
  92. b7N = +1; 
  93. else
  94. b7N = 0; 
  95. return (b7N); 
  96. #endif
  97. }
  98. int s8K(t8B s1, t8B s2, size_t n)
  99. {
  100. int b7N; 
  101. unsigned char c1, c2; 
  102. size_t i = 0; 
  103. do
  104. {
  105. c1 = toupper(s1[i]);
  106. c2 = toupper(s2[i]);
  107. i++;
  108. }
  109. while (c1 && c2 && (c1 == c2) && (i < n));
  110. if (c1 < c2)
  111. b7N = -1; 
  112. else if (c1 > c2)
  113. b7N = +1; 
  114. else
  115. b7N = 0; 
  116. return (b7N); 
  117. }
  118. STRPTR f4F(t8B s1, t8B s2)
  119. {
  120. const char *c1;
  121. const char *c2;
  122. do
  123. {
  124. c1 = s1;
  125. c2 = s2;
  126. while (*c1 != '\0' && (toupper(c1[0]) == toupper(c2[0])))
  127. {
  128. c1++;
  129. c2++;
  130. }
  131. if (*c2 == '\0')
  132. {
  133. return (char *) s1;
  134. }
  135. }
  136. while (*s1++ != '\0');
  137. return NULL;
  138. }
  139. void n4Y(STRPTR s, STRPTR e9R, ULONG p8T)
  140. {
  141. #if v2E
  142. t2B(s, e9R, p8T);
  143. #else
  144. x8C(s);
  145. #endif
  146. }
  147. void j6C(STRPTR * k0Q, t8B t7H, STRPTR e9R, ULONG p8T)
  148. {
  149. #if v2E
  150. n4Y(*k0Q, e9R, p8T); 
  151. *k0Q = v3N(t7H, e9R, p8T); 
  152. #else
  153. x8C(*k0Q); 
  154. *k0Q = s0V(t7H); 
  155. #endif
  156. }
  157. STRPTR t7V(const char ch)
  158. {
  159. static char j2T[2]; 
  160. j2T[0] = ch;
  161. j2T[1] = '\0';
  162. return j2T;
  163. }
  164. STRPTR m6X(t8B str, t8B set)
  165. {
  166. size_t i;
  167. STRPTR result = NULL;
  168. if (str)
  169. {
  170. i = strlen(str) - 1;
  171. while ((i) && (strchr(set, str[i]) == NULL))
  172. i--;
  173. if (strchr(set, str[i]))
  174. result = (STRPTR) & (str[i]);
  175. }
  176. return result;
  177. }
  178. BOOL w8T(STRPTR s, LONG * num)
  179. {
  180. BOOL t8L = FALSE;
  181. errno = 0;
  182. *num = strtol(s, NULL, 10);
  183. if (errno == 0)
  184. {
  185. t8L = TRUE;
  186. }
  187. return t8L;
  188. }
  189. STRPTR k2T(LONG num)
  190. {
  191. static char g6J[10]; 
  192. STRPTR s6T = NULL;
  193. if (sprintf(g6J, "%d", (int) num))
  194. {
  195. s6T = g6J;
  196. }
  197. return s6T;
  198. }
  199. LONG a9B(STRPTR str, STRPTR set, char c0Z, BYTE d1A)
  200. {
  201. STRPTR s = s0V(set);
  202. LONG r5W = 0;
  203. if (s)
  204. {
  205. STRPTR z1W = strtok(s, t7V(c0Z));
  206. LONG count = 1;
  207. while (!r5W && z1W)
  208. {
  209. if (d1A & k3S)
  210. {
  211. if (!r0X(str, z1W))
  212. r5W = count;
  213. }
  214. else if (!strcmp(str, z1W))
  215. r5W = count;
  216. count++;
  217. z1W = strtok(NULL, t7V(c0Z));
  218. }
  219. v3S(s);
  220. }
  221. else
  222. r5W = -1;
  223. return (r5W);
  224. }
  225.